//
//  TBRMyPageControl.m
//  TBRentClient
//
//  Created by tonbright on 2018/5/24.
//  Copyright © 2018年 tonbright. All rights reserved.
//

#import "TBRMyPageControl.h"
#define dotW 11 // 圆点宽
#define dotH 18  // 圆点高
#define magrin 3    // 圆点间距
@implementation TBRMyPageControl

- (void)layoutSubviews
{
    [super layoutSubviews];
    //计算圆点间距
    CGFloat marginX = dotW + magrin;
    
    //计算整个pageControll的宽度
    CGFloat newW = (self.subviews.count - 1 ) * marginX;
    
    //设置新frame
    self.frame = CGRectMake(Width/2-(newW + dotW)/2, self.frame.origin.y, newW + dotW, self.frame.size.height);
    //遍历subview,设置圆点frame
    for (int i=0; i<[self.subviews count]; i++) {
        UIImageView* dot = [self.subviews objectAtIndex:i];
        
        if (i == self.currentPage) {
            [dot setFrame:CGRectMake(i * marginX, dot.frame.origin.y, dotW, dotH)];
        }else {
            [dot setFrame:CGRectMake(i * marginX, dot.frame.origin.y, dotW, dotH)];
        }
    }
}
@end
